<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
</head>

<body>
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left" tapmode onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">消息通知</div>
    </header>
    <div class="aui-bar-nav-d"></div>

    <div class="aui-content">
        <ul class="aui-list aui-list-in">
            <li class="aui-list-item" tapmode onclick="message_trading()">
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-title">交易消息</div>
                    <div class="aui-list-item-right">
                        <div class="aui-badge" style="position:relative;top:0; left:0" id='trading'>0</div>
                    </div>
                </div>
            </li>
            <li class="aui-list-item" tapmode onclick="message_activity()">
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-title">活动消息</div>
                    <div class="aui-list-item-right">
                        <div class="aui-badge" style="position:relative;top:0; left:0" id='activity'>0</div>
                    </div>
                </div>
            </li>
            <li class="aui-list-item" tapmode onclick="message_system()">
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-title">系统消息</div>
                    <div class="aui-list-item-right">
                        <div class="aui-badge" style="position:relative;top:0; left:0" id='system'>0</div>
                    </div>
                </div>
            </li>
        </ul>
    </div>

</body>
<script type="text/javascript">
    apiready = function() {

api.closeToWin({
    name: 'message'
});




        var userid = $api.getStorage('userid');
        api.ajax({
            url: webAddress + '/index.php?ctl=SyntheticMessage&act=unread',
            method: 'post',
            data: {
                values: {
                    uid: userid
                },

            }
        }, function(ret, err) {
            if (ret) {
                for (var i = 0; i < ret.length; i++) {
                    if (ret[i]['message_type'] == 1) {
                        $('#trading').html(ret[i]['count(*)']);
                    }

                    if (ret[i]['message_type'] == 2) {
                        $('#activity').html(ret[i]['count(*)']);
                    }

                    if (ret[i]['message_type'] == 3) {
                        $('#system').html(ret[i]['count(*)']);
                    }
                }
                if ($('#trading').html()=='0') {
                  $("#trading").remove();
                }

                if ($('#activity').html()=='0') {
                  $("#activity").remove();
                }

                if ($('#system').html()=='0') {
                  $("#system").remove();
                }


            } else {
                alert(JSON.stringify(err));
            }
        });



    }


    function message_trading() {
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }
        api.openWin({
            name: 'message_trading',
            url: './message_trading.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            progress: {
                type: "page"
            }
        });
    };

    function message_activity() {
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }
        api.openWin({
            name: 'message_activity',
            url: './message_activity.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            progress: {
                type: "page"
            }
        });
    };

    function message_system() {
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }
        api.openWin({
            name: 'message_system',
            url: './message_system.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            progress: {
                type: "page"
            }
        });
    };

    function closeWin() {
        var setSele = 'randomSwitchBtn(2);';
        api.execScript({
            name: 'root',
            script: setSele,
        });
        api.closeToWin({
            name: 'root'
        });
    }
</script>

</html>
